#include "../logolib/logo_lib.h"
#include "unittest.h"
#include <string.h>

TEST_GROUP (TestBreakPoints)
{
   exe_handle_t   hexe;
   void Setup()
   {
      hexe = create_exe_handle();
      TEST_ASSERT (hexe);
   }
   void TearDown()
   {
     delete_exe_handle(hexe);
     hexe = NULL;
   }
}

TEST_CASE (TestBreakPoints, testToggleBreakPoint) 
{
   debug_toggle_breakpoint(hexe, 1);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   debug_toggle_breakpoint(hexe, 1);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == false);

   debug_toggle_breakpoint(hexe, 2);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);

   debug_toggle_breakpoint(hexe, 3);
   debug_toggle_breakpoint(hexe, 4);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_toggle_breakpoint(hexe, 3);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_toggle_breakpoint(hexe, 2);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_toggle_breakpoint(hexe, 4);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == false);
}

TEST_CASE (TestBreakPoints, testAdjustBreakPoints) 
{
   debug_toggle_breakpoint (hexe, 1);
   debug_toggle_breakpoint (hexe, 2);
   debug_toggle_breakpoint (hexe, 3);

   debug_adjust_breakpoints (hexe, true, 1);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_adjust_breakpoints (hexe, false, 1);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == false);

   debug_adjust_breakpoints (hexe, true, 3);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_adjust_breakpoints (hexe, true, 5);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == true);

   debug_adjust_breakpoints (hexe, false, 1);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == false);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 4) == false);

   debug_adjust_breakpoints (hexe, false, 2);
   TEST_ASSERT (debug_find_breakpoint(hexe, 1) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 2) == true);
   TEST_ASSERT (debug_find_breakpoint(hexe, 3) == false);
}
